Array.prototype.myReduce = function (cb, initalVal) {
    if (typeof cb !== 'function') {
        throw TypeError('callback must be a function')
    }
    let arr = this
    let pre = initialValue || arr[0]
    for (let i = initalVal ? 0 : 1; i < arr.length; i++) {
        pre = cb(pre, arr[i], i, arr)
    }
    return pre
}